from django.contrib import admin
from booktest.models import BookInfo,HeroInfo

# Register your models here.

class HeroInfoInline(admin.TabularInline):          # 设置Hero内嵌到Book的方式为表格
    model = HeroInfo
    extra = 3                                       # 3个添加栏

class BookInfoAdmin(admin.ModelAdmin):
    list_display = ['id','btitle','bpub_date']      # 设置列表显示的字段, 默认样式只有id
    list_filter = ['btitle']                        # 设置过滤字段窗口, 指定过滤字段为btitle
    search_fields = ['btitle']                      # 设置字段搜索框, 指定搜索字段为btitle
    list_per_page = 10                              # 设置分页
    fieldsets = [                                   # 分组
        ('base',{'fields':['btitle']}),
        ('super',{'fields':['bpub_date']})
    ]
    inlines = [HeroInfoInline]                      # 内嵌Hero的add表单




class HeroInfoAdmin(admin.ModelAdmin):
    list_display = ['id', 'hname', 'gender', 'hcontent']


admin.site.register(BookInfo,BookInfoAdmin)         # 表BookInfo使用自定义页面样式BookInfoAdmin
admin.site.register(HeroInfo)                       # 表HeroInfo使用默认页面样式



